apollo_app_list() {
  local base_url="$1"
  shift

  local url="${base_url}/openapi/v1/apps"

  curl -X GET "$url" -H "Content-Type: application/json" "$@"
}

apollo_namespace_list() {
  local base_url="$1"
  local env="$2"
  local appId="$3"
  local clusterName="$4"
  shift 4

  local url="${base_url}/openapi/v1/envs/${env}/apps/${appId}/clusters/${clusterName}/namespaces"

  curl -X GET "$url" -H "Content-Type: application/json" "$@"
}

apollo_namespace() {
  local base_url="$1"
  local env="$2"
  local appId="$3"
  local clusterName="$4"
  local namespaceName="$5"
  shift 5

  local url="${base_url}/openapi/v1/envs/${env}/apps/${appId}/clusters/${clusterName}/namespaces/${namespaceName}"

  curl -X GET "$url" -H "Content-Type: application/json" "$@"
}

apollo_namespace_release() {
  local base_url="$1"
  local env="$2"
  local appId="$3"
  local clusterName="$4"
  local namespaceName="$5"
  local data="$6"
  shift 6

  local url="${base_url}/openapi/v1/envs/${env}/apps/${appId}/clusters/${clusterName}/namespaces/${namespaceName}/releases"

  curl -X POST "$url" -H "Content-Type: application/json" -d "$data" "$@"
}

apollo_modify_namespace_item() {
  local base_url="$1"
  local env="$2"
  local appId="$3"
  local clusterName="$4"
  local namespaceName="$5"
  local key="$6"
  local data="$7"
  shift 7

  local url="${base_url}/openapi/v1/envs/${env}/apps/${appId}/clusters/${clusterName}/namespaces/${namespaceName}/items/${key}"

  curl -X PUT "$url" -H "Content-Type: application/json" -d "$data" "$@"
}

apollo_namespace_item() {
  local base_url="$1"
  local env="$2"
  local appId="$3"
  local clusterName="$4"
  local namespaceName="$5"
  local key="$6"
  shift 6

  local url="${base_url}/openapi/v1/envs/${env}/apps/${appId}/clusters/${clusterName}/namespaces/${namespaceName}/items/${key}"

  curl -X GET "$url" -H "Content-Type: application/json" "$@"
}

http_get() {
    local url = "$1"
    shift
    
    curl -X GET "$url" "$@"
}

http_post() {
  local url = "$1"
  shift

  curl -X POST "$url" "$@"
}

http_put() {
  local url = "$1"
  shift

  curl -X PUT "$url" "$@"
}

http_delete() {
    local url = "$1"
    shift

    curl -X DELETE "$url" "$@"
}
